package com.example.book.controller;

import com.example.book.domain.Book;
import com.example.book.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("book")
public class BookController {
    @Autowired
    private BookService bookService;

    @GetMapping("/getBookByBookId/{id}")
    public Book getBookByBookId(@PathVariable("id")Long id){
        return bookService.getBookByBookId(id);
    }

    @GetMapping("/getBookByBookName/{name}/{userId}")
    public List<Book> getBookByBookName(@PathVariable("name")String name,@PathVariable("userId")Integer userId){
        return bookService.getBookByBookName(name,userId);
    }

    @GetMapping("/{userId}")
    public List<Book> getBooksByUserId(@PathVariable("userId")Long userId){
        return bookService.getBooksByUserId(userId);
    }

    @PostMapping("/add")
    public int addBook(@RequestBody Book book){
        return bookService.addBook(book);
    }

    @DeleteMapping("/remove/{bookId}")
    public int removeBookByBookId(@PathVariable("bookId")Long bookId){
        return bookService.removeBookByBookId(bookId);
    }

    @PostMapping("/update")
    public int updateBookByBookId(@RequestBody Book book){
        return bookService.updateBookByBookId(book);
    }
}
